package com.example.crm.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.example.crm.entity.User;
import com.example.crm.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
public class DataController {
    @Resource
    private UserService userService;

    @GetMapping("/getData")
    public ResponseEntity<List> getData() {
        List<Map<String, Object>> list = userService.listMaps();
        return ResponseEntity.ok(list);
    }


    @PostMapping("/addData")
    public ResponseEntity<String> addData(@RequestBody User user) {
        boolean save = userService.save(user);
        if(save){
            return ResponseEntity.ok("Ok");
        }else{
            return ResponseEntity.ok("noOk");
        }
    }

    @PostMapping("/deleteData")
    public ResponseEntity<String> deleteData(@RequestBody User user) {
        boolean delete = userService.removeById(user.getId());
        if(delete){
            return ResponseEntity.ok("Ok");
        }else{
            return ResponseEntity.ok("noOk");
        }
    }

    @PostMapping("/updateData")
    public ResponseEntity<String> updateData(@RequestBody User user) {
        boolean update = userService.updateById(user);
        if(update){
            return ResponseEntity.ok("Ok");
        }else{
            return ResponseEntity.ok("noOk");
        }
    }

}
